var log4js = require('log4js');

log4js.configure({
    appenders: {
        stdout: { type: 'stdout' },
        everything: { type: 'file', filename: 'smtool_all.log', maxLogSize: 10485760, backups: 5 },
        emergencies: {  type: 'file', filename: 'smtool_error.log', maxLogSize: 10485760, backups: 5 },
        errors: { type: 'logLevelFilter', appender: 'emergencies', level: 'error' }
    },
    categories: {
        default: { appenders: ['stdout', 'everything', 'errors'], level: 'debug' }
    }
});

const logger = log4js.getLogger('console');

logger.replaceConsole = function (isReplaceConsole) {
    if (!isReplaceConsole) return;
    console.log = logger.info.bind(logger);
    console.info = logger.info.bind(logger);
    console.debug = logger.debug.bind(logger);
    console.warn = logger.warn.bind(logger);
    console.error = logger.error.bind(logger);
    console.trace = logger.error.bind(logger);
}

module.exports = logger;